<template>
  <div>
    <el-row>
      <!--左侧内容-->
      <el-col :span="8" style="padding-right: 10px">
        <el-card class="box-card">
          <div class="user">
            <img src="~/assets/logo.png" alt="" />
            <div class="userInfo">
              <p class="name">Admin</p>
              <p class="role">超级管理员</p>
            </div>
          </div>
          <div class="loginInfo">
            <p>上次登录时间<span>2021-01</span></p>
            <p>上次登录地点<span>武汉</span></p>
          </div>
        </el-card>
        <!--下面表格内容-->
        <el-card class="myCard">
          <el-table :data="tableData" stripe style="width: 100%">
            <el-table-column prop="date" label="日期"> </el-table-column>
            <el-table-column prop="name" label="姓名"> </el-table-column>
            <el-table-column prop="address" label="地址"> </el-table-column>
          </el-table>
        </el-card>
      </el-col>
      <!--右侧内容-->
      <el-col :span="16" style="padding-left: 10px">
        <div class="count">
          <el-card
            v-for="(item, index) in countData"
            :key="index"
            :body-style="{ display: 'flex', padding: 0 }"
          >
            <i
              class="icon"
              :class="`el-icon-${item.icon}`"
              :style="{ background: item.color }"
            >
            </i>
            <div class="detail">
              <p class="price">${{ item.value }}</p>
              <p class="name">{{ item.name }}</p>
            </div>
          </el-card>
        </div>
        <!--图标-->
        <el-card style="height: 220px">
          <div ref="echatLine" style="height: 220px"></div>
        </el-card>
        <div class="graph" style="height: 190px">
          <el-card>
            <div ref="echatBar" style="height: 190px"></div>
          </el-card>
          <el-card style="height: 190px">
            <div ref="echatPie" style="height: 190px"></div>
          </el-card>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getHomeData } from "network/Home.js";
import * as echarts from "echarts";
export default {
  name: "VueSysmangerHome",

  data() {
    return {
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
      countData: [
        {
          name: "今日支付订单",
          value: "225",
          icon: "success",
          color: "#2ec7c9",
        },
        {
          name: "今日支付订单",
          value: "225",
          icon: "success",
          color: "#2ec7c9",
        },
        {
          name: "今日支付订单",
          value: "225",
          icon: "success",
          color: "#2ec7c9",
        },
        {
          name: "今日支付订单",
          value: "225",
          icon: "success",
          color: "#2ec7c9",
        },
        {
          name: "今日支付订单",
          value: "225",
          icon: "success",
          color: "#2ec7c9",
        },
        {
          name: "今日支付订单",
          value: "225",
          icon: "success",
          color: "#2ec7c9",
        },
      ],
      xAxis: [],
      series: [],
    };
  },
  mounted() {
    // getHomeData().then((data) => {
    //   this.lineCharts(data.data.orderData);
    //   this.barCharts(data.data.userData);
    //   this.pinCharts(data.data.videoData);
    // });
  },

  methods: {
    lineCharts(orderData) {
      this.xAxis = Object.keys(orderData.data[0]);
      this.xAxis.forEach((key) => {
        this.series.push({
          name: key,
          type: "line",
          data: orderData.data.map((item) => item[key]),
        });
      });
      // 指定图表的配置项和数据
      const lineOption = {
        tooltip: {},
        legend: {
          data: this.xAxis,
        },
        xAxis: {
          data: orderData.date,
        },
        yAxis: {},
        series: this.series,
      };
      const myChart = echarts.init(this.$refs.echatLine);
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(lineOption);
    },
    barCharts(userData) {
      //柱状图
      const myChartBar = echarts.init(this.$refs.echatBar);
      const barOption = {
        title: {
          text: "第一个",
        },
        tooltip: {},
        legend: {
          //图例文字颜色
          textStyle: {
            color: "#333",
          },
        },
        grid: {
          left: "20%",
        },
        //提示框
        tooltip: {
          trigger: "axis",
        },
        xAxis: {
          type: "category",
          data: userData.map((item) => item.data),
          axisLine: {
            lineStyle: {
              color: "#17b3a3",
            },
          },
          axislabel: {
            interval: 0,
            color: "#333",
          },
        },
        yAxis: {
          type: "category",
          axisLine: {
            lineStyle: {
              color: "#17b3a3",
            },
          },
        },
        color: ["#2ec7c9", "#b6a2de"],
        series: [
          {
            name: "新增用户",
            data: userData.map((item) => item.new),
            type: "bar",
          },
          {
            name: "活跃用户",
            data: userData.map((item) => item.active),
            type: "bar",
          },
        ],
      };
      myChartBar.setOption(barOption);
    },
    pinCharts(videoData) {
      //饼状图
      const myChartPie = echarts.init(this.$refs.echatPie);
      // let pieOption = {
      //   tooltip: {
      //     trigger: "item",
      //   },
      //   color: [
      //     "#0f78f4",
      //     "#dd536b",
      //     "#9462b5",
      //     "#95262e5",
      //     "#5462e5",
      //     "#1462e5",
      //     "#3e62e5",
      //   ],
      //   series: [
      //     {
      //       type: "pie",
      //       data: videoData,
      //     },
      //   ],
      // };
      //指定图表的配置项和数据;
      var optionPie = {
        series: [
          {
            name: "访问来源",
            type: "pie",
            radius: "55%",
            data: videoData,
            roseType: "angle",
            itemStyle: {
              normal: {
                shadowBlur: 200,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };

      myChartPie.setOption(optionPie);
    },
  },
};
</script>
<style lang="less" scoped>
.myCard {
  margin-top: 20px;
}
.user {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid #ccc;
  img {
    margin-right: 40px;
    border-radius: 50%;
    height: 150px;
    width: 150px;
  }
  .userInfo {
    .name {
      font-size: 32px;
    }
    .role {
      color: #999999;
    }
  }
}

.loginInfo {
  p {
    line-height: 28px;
    font-size: 14px;
    color: #999999;
    span {
      color: #666666;
      margin-left: 60px;
    }
  }
}

.count {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between; //两边贴边
  .el-card {
    width: 32%;
    margin-bottom: 20px;
  }
  .icon {
    width: 80px;
    height: 80px;
    font-size: 30px;
    text-align: center;
    line-height: 80px;
    color: #fff;
  }
  .detail {
    display: flex;
    flex-direction: column; //flex 布局，主轴方向 上下
    margin-left: 15px;
    .price {
      font-size: 30px;
      margin-bottom: 10px;
      height: 30px;
      line-height: 30px;
    }
    .name {
      font-size: 14px;
      color: #999;
      text-align: center;
    }
  }
}

.graph {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  .el-card {
    width: 48%;
  }
}
</style>